<template>
  <div class="main">
    <div class="container">
      <span><a-icon type="home"/>首页 / 视频详情</span>
      <div class="main-middle">
        <span @click="collect" ref="collect"><a-icon type="heart"/>收藏</span>
        <div class="pic"><img :src="course.bannerFileUrl" alt=""></div>
        <h2 class="title">{{ course.courseTitle }}</h2>

        <span class="study">累计{{ course.orderBy }}人学习</span>
        <a-rate :default-value="4" disabled/>

        <h2 class="free">免费</h2>
        <router-link to="/video" tag="button"> 立即观看</router-link>
      </div>
      <div class="main-buttom">
        <a-tabs default-active-key="1" @change="callback">
          <a-tab-pane key="1" tab="课程详情">
            <!-- 课程详情 -->
            <div class="direction" v-html="course.courseDetail">

            </div>
          </a-tab-pane>
          <a-tab-pane key="2" tab="目录" force-render>
            <!-- 目录 -->
            <div class="catalogue">
              <ul v-for="(item,index) in titleList" :key="index">
                <h2>{{ index + 1 }}.{{ item.sectionName }}</h2>
                <li v-for="(item,index1) in item.subSections" :key="index1">
                  {{ index + 1 }}-{{ index1 + 1 }}.{{ item.sectionName }}
                </li>
              </ul>
            </div>
          </a-tab-pane>
          <a-tab-pane key="3" tab="评论">
            <!-- 评论 -->
            <div class="comment">
              <span>评论</span>
              <div>
                <a-rate :default-value="4" disabled/>
                <span>非常好</span></div>
              <a-textarea placeholder="请发表你对课程的看法" :rows="4"/>
              <div class="publish">
                <button class="publishComment">发表评论</button>
              </div>
              <div class="commentDetial">
                <ul class="commentContent">
                  <li class="commentlist" v-for="(item,index) in commentlist" :key="index">
                      <a-avatar style="margin-top: 10px;margin-right: 10px"
                        :src="item.user.avatarUrl || 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png'"/>
                    {{item.user.nickname }}
                    <a-rate :default-value="5" disabled style="float: right"/>
                    <div class="content">{{ item.commentContent }}</div>
                    <span style="float: right;left: -5px">2021-03-05 15:04 回复</span>
                  </li>
                </ul>
              </div>
            </div>

          </a-tab-pane>
        </a-tabs>


      </div>
    </div>

  </div>
</template>

<script>
import {commentDetail, detail} from "@/api/api";

export default {
  name: "Detail",
  data() {
    return {
      course: {},
      titleList: [],
      commentlist: []
      // nameList:{},
    }
  },
  methods: {
    callback(key) {
      key;
    },
    collect() {
      if (!this.$store.state.isLogin) {
        this.$store.commit("changeShowLogin", true)
      } else {
        this.$refs.collect.style.color = "red"
        this.$refs.collect.style.border = "1px solid red"
      }
    },
  },
  created() {
    detail(this.$route.params.id).then(res => {
      this.course = res.data
      this.titleList = this.course.sections
    }),
        commentDetail(this.$route.params.id).then(res => {
          console.log(res.rows)
          this.commentlist = res.rows
          console.log(this.commentlist)
        })
  },

}
</script>

<style scoped lang="less">
.main {
  background-color: #eee;
  padding-top: 10px;

  .container {
    width: 1200px;
    margin: auto;
    position: relative;

    span {
      margin-left: -1088px;
      color: rgba(0, 0, 0, .45);
    }

    .main-middle {
      overflow: hidden;
      position: relative;
      background-color: white;
      margin-top: 20px;
      padding-bottom: 20px;

      span {
        position: absolute;
        right: 20px;
        top: 20px;
        width: 100px;
        height: 30px;
        border: 1px solid #999;
        text-align: center;
        line-height: 30px;
      }

      .pic {
        width: 330px;
        height: 200px;
        background-color: #444546;
        margin: 20px;
        margin-top: 38px;
        float: left;

        img {
          width: 100%;
          height: 100%;
        }
      }

      .study {
        position: absolute;
        right: 710px;
        top: 65px;
        border: 0;
      }

      .title {
        //width: 350px;
        float: left;
        margin-left: 24px;
        margin-top: 30px;
      }

      ul {
        overflow: hidden;
        position: absolute;
        top: 62px;
        left: 500px;

      }


    }

    .free {
      position: absolute;
      top: 100px;
      left: 392px;
      color: rgb(0, 207, 140);
    }

    button {
      width: 160px;
      height: 45px;
      font-size: 18px;
      margin-right: 10px;
      color: #fff;
      background-color: #00a879;
      border: 0;
      text-align: center;
      line-height: 45px;
      position: absolute;
      top: 193px;
      left: 392px;
    }
  }

  .main-buttom {
    margin-top: 20px;
    background-color: white;
    text-align: left;

    ul {
      overflow: hidden;
      border-bottom: 1px solid rgba(0, 0, 0, .45);
      padding-left: 30px;

      li {
        float: left;
        width: 92px;
        height: 50px;
        text-align: center;
        line-height: 50px;
        font-size: 16px;
        color: rgba(0, 0, 0, .45);

        &:hover {
          cursor: pointer;
        }
      }
    }

    .green {
      color: #00a879;
      border-bottom: 2px solid #00a879;
    }


    .direction {
      padding: 20px 30px;
      color: rgba(0, 0, 0, .45);
      // display: none;
    }

    .catalogue {
      margin: 40px 63px;
      //display: none;
      ul {
        border: 0;

        li {
          width: 100%;
          height: 50px;
          background-color: rgba(0, 0, 0, .1);
          margin-top: 10px;
          line-height: 50px;
          font-size: 14px;
          color: rgba(0, 0, 0, .45);
          padding-left: 23px;
          text-align: left;
        }
      }
    }

    .comment {
      padding: 30px 30px;
      overflow: hidden;
      //display: none;

      ul {
        border-bottom: 0;
        padding: 0;
      }

      span {
        margin: 0;
        position: relative;
        top: -8px;
        left: 5px;
      }

      textarea {
        height: 136px;
        min-height: 136px;
        max-height: 136px;
        overflow-y: hidden;
        border-color: #23db9b;
        border-right-width: 1px !important;
      }

      button {
        float: right;
        margin: 20px 0px 0px;
        width: 100px;
        height: 30px;
        background-color: #23db9b;
        border: 0;
        color: white;
      }

      .publish {
        height: 60px;
        overflow: hidden;
        position: relative;

        .publishComment {
          float: right;
          position: absolute;
          top: 0;
          //right: 0;
          left: 1000px;
          line-height: 20px;
        }
      }

      .commentDetial {
        width: 100%;
        //height: 200px;
        padding: 20px;

        .commentContent {
          width: 100%;
          height: 100%;

          .commentlist {
            width: 100%;
            height: 100%;
            text-align: left;
            border-top: 1px solid gray;

            .content {
              width: 100%;
              height: 47%;
              padding: 10px 40px;
            }
          }
        }

      }
    }
  }
}

</style>